home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok24.lha
/
DME
/
SRC
/
source.zoo
/
m2err.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-07-03
|
6KB
|
325 lines
#include "defs.h"
#define MSGFILE "M2:Fehler-Meldungen"
extern IBASE *IntuitionBase;
extern PROC *proc;
ubyte *msgfile = NULL;
void
err_insline()
{
register m2_error *err;
register int line = Ep->Line;
register int i;
/* search first error */
err = Ep->err_list;
i = 1;
while((err->line < line) && ( i <= Ep->err_num)) {
i++;
err++;
}
/* increment following error-lines */
while( i <= Ep->err_num ) {
if(err->line != -1)
err->line++;
err++;
i++;
}
}
void
err_deline(line)
int line;
{
register m2_error *err;
register int i;
/* search first error */
err = Ep->err_list;
i = 1;
while((err->line < line) && ( i <= Ep->err_num)) {
i++;
err++;
}
if(err->line == line) {
err->line = -1;
i++;
err++;
}
/* decrement following error-lines */
while( i <= Ep->err_num ) {
if(err->line != -1)
err->line--;
err++;
i++;
}
}
void
calc_xy(col,row,pos)
long *col;
long *row;
long pos;
{
register long len;
register long count;
register ubyte **line;
count = 0;
*col = 0;
*row = 0;
line = Ep->List;
do {
len = strlen(*(line++))+1;
count += len;
(*row)++;
} while(count < pos);
(*row)--;
*col = pos - (count - len);
}
get_errmsg(str,num)
ubyte *str;
uword num;
{
register ubyte *err, *nexterr;
register short found = 0;
err = (ubyte *) msgfile;
while( ((nexterr = *(ulong *) err+msgfile) != (ubyte *)NULL )
&& (!found)) {
if( *(uword *)(err+4) == num) {
strcpy(str,err+6);
strcat(str," ");
found = -1;
}
err = nexterr;
}
if(!found)
strcpy(str,"Unknown error ");
}
ubyte *read_buffer(name,len,errstr)
ubyte *name;
ulong *len;
ubyte *errstr;
{
register struct FileLock *lock,*Lock();
register struct FileHandle *handle,*Open();
register struct FileInfoBlock *fib;
register ubyte *buf = 0;
register ubyte str[80];
proc->pr_WindowPtr = (APTR)Ep->Win;
if( lock = Lock(name,SHARED_LOCK)) {
fib = malloc(sizeof(struct FileInfoBlock));
Examine(lock,fib);
if(buf = (ubyte *) malloc(fib->fib_Size)) {
handle = Open(name, MODE_OLDFILE);
*len = Read(handle,buf,fib->fib_Size);
if(*len != fib->fib_Size) {
strcpy(str,"error reading ");
strcat(str, name);
title(str);
Abortcommand = 1;
free(buf);
buf = 0;
}
Close(handle);
} else {
title("Out of memory error");
Abortcommand = 1;
}
free(fib);
UnLock(lock);
} else {
title(errstr);
Abortcommand = 1;
}
return(buf);
}
uword
read_errfile()
{
register long count;
register ubyte *ptr,*pos;
register m2_error *m2err,*m2err2;
long len;
ubyte str[100];
len = strlen(Ep->Name);
/* is suffix = ".def" or ".mod" ? */
if(len <= 4)
return (uword)0;
if(ncstrcmp(&Ep->Name[len-4],".DEF") && ncstrcmp(&Ep->Name[len-4],".MOD"))
return (uword)0;
/* read error-file */
strcpy(str,Ep->Name);
strcat(str,"e");
if(!(ptr = read_buffer(str,&len,"No errors")))
return (uword)0;
if( *(ulong *)ptr != M2_ERRFILE ) {
strcat(str, " is no error-file");
title(str);
free(ptr);
return (uword)0;
}
/* read message-file */
strcpy(str,MSGFILE);
strcat(str," not found");
if(!msgfile)
if(!(msgfile = read_buffer(MSGFILE,&len,str)))
return (uword)0;
pos = ptr + 4;
count = 0;
while(pos < (ptr+len)) {
if(*(ulong *)pos == M2_ERR)
count ++;
pos+=2;
}
sprintf(str,"%ld errors",count);
title(str);
if(!( m2err = (m2_error *) malloc(count*sizeof(m2_error)))) {
title("Not enough memory for error-list");
return (uword)0;
}
Ep->err_list = m2err;
Ep->err_num = 0;
Ep->last_err = -1;
pos = ptr + 4;
while(pos < (ptr+len)) {
if(*(uword *)pos == M2_EOF)
break;
if(*(ulong *)pos != M2_ERR) {
title("Format-error in errorfile");
return (uword)0;
}
pos += 4;
calc_xy(&m2err->column,&m2err->line,*(ulong *)pos);
pos += 4;
sprintf(m2err->msg,"%ld : ",(long)*(uword *)pos);
do {
if(*pos == M2_STR) {
pos++;
strcat(&m2err->msg[strlen(m2err->msg)],pos);
while(*pos)
pos++;
pos++;
if(!(*pos))
pos++;
} else {
get_errmsg(&(m2err->msg[strlen(m2err->msg)]),*(uword *)pos);
pos += 2;
}
} while( (*(ulong *)pos != M2_ERR) && (*(uword *)pos != M2_EOF) );
m2err ++;
Ep->err_num++;
}
free(ptr);
return (uword)count;
}
void err_quit()
{
free(Ep->err_list);
Ep->err_list = 0;
Ep->err_num = 0;
}
do_firsterr()
{
if(Ep->err_num) {
Ep->last_err = -1;
do_nexterr();
} else {
title("No errors");
Abortcommand = 1;
}
}
do_nexterr()
{
if(Ep->err_num) {
if(Ep->last_err < Ep->err_num)
Ep->last_err++;
do_currenterr();
} else {
title("No errors");
Abortcommand = 1;
}
}
do_preverr()
{
if(Ep->err_num) {
if(Ep->last_err > 0) {
Ep->last_err--;
do_currenterr();
} else {
title("Already first error");
}
} else {
title("No errors");
Abortcommand = 1;
}
}
do_currenterr()
{
m2_error *err;
if (IntuitionBase->ActiveWindow != Ep->Win) {
WindowToFront(Ep->Win);
ActivateWindow(Ep->Win);
}
if(Ep->err_num == 0) {
title("No errors");
Abortcommand = 1;
} else {
if(Ep->last_err == -1)
Ep->last_err = 0;
if(Ep->err_num == -1) {
title("Errorfile confused because of block-operations");
Abortcommand = 1;
return;
}
if(Ep->last_err >= Ep->err_num) {
title("No more errors");
Abortcommand = 1;
} else {
text_sync();
err = Ep->err_list + Ep->last_err;
if(err->line == -1) {
do_nexterr();
} else {
Ep->Column = err->column;
if(err->line <= Ep->Lines) {
Ep->Line = err->line;
text_load();
text_sync();
title(err->msg);
}
}
}
}
}